package org.jeecg.modules.kuybFeilb.service.impl;


import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.jeecg.modules.kuybCityStandard.entity.KuybCityStandard;
import org.jeecg.modules.kuybCityStandard.service.IKuybCityStandardService;
import org.jeecg.modules.kuybFeilb.entity.KuybFeilb;
import org.jeecg.modules.kuybFeilb.mapper.KuybFeilbMapper;
import org.jeecg.modules.kuybFeilb.service.IKuybFeilbService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.Iterator;
import java.util.List;

/**
 * @Description: kuyb_feilb
 * @Author: jeecg-boot
 * @Date:   2021-09-13
 * @Version: V1.0
 */
@Service
public class KuybFeilbServiceImpl extends ServiceImpl<KuybFeilbMapper, KuybFeilb> implements IKuybFeilbService {

    @Autowired
    KuybFeilbMapper feilbMapper;

    @Autowired
    IKuybCityStandardService cityStandardService;

    @Override
    public KuybFeilb getPremiumByParam(KuybFeilb kuybFeilb) {

        KuybFeilb feilb= feilbMapper.getPremiumByParam(kuybFeilb);
        if(feilb==null || kuybFeilb.getServiceLifeStart()>60){
            return null;
        }
        /*else if(kuybFeilb.getServiceLifeStart()>=24 && feilb.getNengylx().equals(1)){
            feilb.setPremium(feilb.getPremium().multiply(new BigDecimal(1.2)));
        }else if(kuybFeilb.getServiceLifeStart()>=12  && feilb.getNengylx().equals(1)){
            feilb.setPremium(feilb.getPremium().multiply(new BigDecimal(1.1)));
        }*/
        if(feilb!=null)
        feilb.setPremium(feilb.getPremium().setScale(0,BigDecimal.ROUND_HALF_UP));

        return feilb;
    }

    @Override
    public List<KuybFeilb> getStandards(KuybFeilb kuybFeilb) {
        List<KuybFeilb> feilbs=feilbMapper.getStandards(kuybFeilb);
        List<KuybCityStandard> cityStandards= cityStandardService.getCStandardByCityId(kuybFeilb.getCity());
        if(feilbs!=null && feilbs.size()>0){
            if(cityStandards!=null && cityStandards.size()>0){
                for (int i = 0; i < cityStandards.size(); i++) {
                    for (int j = feilbs.size()-1; j >=0 ; j--) {
                        if(cityStandards.get(i).getStandatdId().equals(feilbs.get(j).getPolicyTimeMileage())){
                            feilbs.remove(j);
                        }
                    }
                }
            }
        }

        return feilbs;
    }
}
